package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.user.UserListenProcess;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user")
@SuppressWarnings({"all"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;

    /**
     * 获取用户最近一次播放记录
     * /api/user/userListenProcess/getLatelyTrack
     */
    @GetMapping("/userListenProcess/getLatelyTrack")
    @GuiguLogin
    public Result<Map<String,Long>> getLatelyTrack(){
        Long userId = AuthContextHolder.getUserId();
        Map<String,Long> map = userListenProcessService.getLatelyTrack(userId);
        return Result.ok(map);
    }



    /**
     * 更新播放进度
     * /api/user/userListenProcess/updateListenProcess
     */
    @PostMapping("/userListenProcess/updateListenProcess")
    @GuiguLogin(required = false)
    public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo){
        Long userId = AuthContextHolder.getUserId();
        if (userId!=null){
            userListenProcessService.updateListenProcess(userListenProcessVo,userId);
        }
        return Result.ok();
    }


    /**
     * 获取声音的上次跳出时间
     * /api/user/userListenProcess/getTrackBreakSecond/{trackId}
     */
    @GuiguLogin(required = false)
    @GetMapping("/userListenProcess/getTrackBreakSecond/{trackId}")
    public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId){
        Long userId = AuthContextHolder.getUserId();
        BigDecimal bigDecimal = userListenProcessService.getTrackBreakSecond(trackId,userId);
        return Result.ok(bigDecimal);
    }




}

